home *** CD-ROM | disk | FTP | other *** search
- /*
- * simple box class for the Objects-in-C tester
- *
- * Copyright © John Wainwright 1988
- *
- */
-
- #include "oic.h"
- #include "generics.h"
-
- typedef struct /* box IV's */
- {
- object tl;
- object br;
- } box_i;
- typedef object box;
-
- class Box;
-
- defGeneric(offset, offsetGeneric, "offset")
-
- /* ------------------------------ Box Ops -------------------------------- */
-
- static box
- _new(self, b, ap)
- box self;
- box_i *b;
- struct
- {
- double top;
- double left;
- double bottom;
- double right;
- } *ap;
- {
- extern class Coord;
-
- b->tl = New(Coord, ap->left, ap->top);
- b->br = New(Coord, ap->right, ap->bottom);
- return Super(self);
- }
-
- static box
- _offset(self, b, args)
- box self;
- box_i *b;
- struct {double dx; int dy;} *args;
- {
- offset(b->tl, args->dx, args->dy);
- offset(b->br, args->dx, args->dy);
- }
-
- static box
- _draw(self, b)
- box self;
- box_i *b;
- {
- Rect r;
-
- r.top = yCoord(b->tl);
- r.left = xCoord(b->tl);
- r.bottom = yCoord(b->br);
- r.right = xCoord(b->br);
-
- FrameRect(&r);
- }
-
- static string
- _replist(self, b)
- box self;
- box_i *b;
- {
- register replist replist;
-
- replist = New(Replist, "{", "}", ".");
- add(replist, repList(b->tl), repList(b->br), END);
- return replist;
- }
-
- /*------------------------------ Init Classes --------------------------------*/
-
- InitBoxClass()
- {
- Box = NewClass(sizeof(box_i), 0, "Box", IndexMixin, END);
- AddMethods(Box,
- newGeneric, _new,
- drawGeneric, _draw,
- offsetGeneric, _offset,
- repListGeneric, _replist,
- END);
- }
-